home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PRINTER / NEWPRT10.ARJ / LOWLEVEL.CPP < prev    next >
C/C++ Source or Header  |  1992-02-17  |  3KB  |  148 lines

  1.  
  2. //Copyright 1991-1992 Roger Bedell All rights reserved
  3. //See the attached readme file for licensing information.
  4.  
  5. #include "io.h"
  6. #include "time.h"
  7. #include "stdio.h"
  8. #include "dos.h"
  9. #include "string.h"
  10. #include "bios.h"
  11. #include "mem.h"
  12.  
  13. #define NONFATAL 1
  14. #define FATAL 0
  15. #define EJECT 1
  16.  
  17. int send_cmd( char *line_buffer, int length );
  18. int opn_prt(char * path ,int i);
  19. int cls_prt(int flag);
  20. int flush_buf(void);
  21.  
  22. int printer_error_message(char *, int);
  23. int error_message(char *, int);
  24.  
  25. //lpt1 file descriptor
  26. int lpt1_fd;
  27.  
  28. int bbprinter_number; //needs to be set before entering routines
  29.  
  30. int opn_prt(char * path ,int i)
  31. {
  32.  
  33.     //use the bios routines
  34.     //try to init it (actually, just get its status)
  35.     int status = _bios_printer(2 , bbprinter_number, 0);
  36.  
  37.     if(status & 0x01 )
  38.     {   //time out
  39.         printer_error_message("Couldnt open printer - Timed out.",NONFATAL);
  40.         return -1;
  41.     }
  42.     if(status & 0x20 )
  43.     {   //paper out
  44.         printer_error_message("Couldnt open printer - Paper out.",NONFATAL);
  45.         return -1;
  46.     }
  47.  
  48.     if(status & 0x08 )
  49.     {   //IO error
  50.         printer_error_message("Couldnt open printer - Not on line.",NONFATAL);
  51.         return -1;
  52.     }
  53.  
  54.  
  55.     return 1;
  56. }
  57.  
  58. int cls_prt(int flag)
  59. {
  60.     char * buffer = "\f";
  61.     int count;
  62.  
  63.     count = strlen(buffer);
  64.  
  65.  
  66.     if(flag == EJECT)
  67.     {
  68.         //send a line feed
  69.         send_cmd(buffer, count);
  70.  
  71.     }
  72.  
  73.     return 1;
  74. }
  75.  
  76.  
  77. int send_cmd( char *line_buffer, int length )
  78. {
  79.  
  80.     int i;
  81.     while( length > 0)
  82.     {
  83.         //make sure the printer is ready
  84.         int status = _bios_printer(2 , bbprinter_number, 0);
  85.  
  86.         if(status  & 0x80 )
  87.         {   //not busy
  88.             //print
  89.             _bios_printer(0 , bbprinter_number, *line_buffer++);
  90.  
  91.             length--;
  92.         }
  93.         if(status & 0x01 )
  94.         {   //time out
  95.             printer_error_message("Couldnt print - Timed out.",NONFATAL);
  96.             return -1;
  97.         }
  98.         if(status & 0x20 )
  99.         {   //paper out
  100.             printer_error_message("Couldnt print - Paper out.",NONFATAL);
  101.             return -1;
  102.         }
  103.  
  104.         if(!(status & 0x10) )
  105.         {   //not selected
  106.             printer_error_message("Couldnt print - Not Selected.",NONFATAL);
  107.             return -1;
  108.         }
  109.  
  110.         if(status & 0x08 )
  111.         {   //IO error
  112.             printer_error_message("Couldnt print - Not on line.",NONFATAL);
  113.             return -1;
  114.         }
  115.  
  116.  
  117.     }
  118.  
  119.     return 1;
  120. }
  121.  
  122. int flush_buf(void)
  123. {
  124. //dont need to
  125.     return 1;
  126. }
  127.  
  128. #ifdef testprint
  129. void main()
  130. {
  131.     opn_prt("lpt1", 0);
  132.     send_cmd("Hello",5);
  133.     cls_prt(EJECT);
  134. }
  135.  
  136.  
  137. #endif
  138.  
  139. //global printer error flag
  140. int printer_error_flag = 0;
  141.  
  142. int printer_error_message(char *junk, int j)
  143. {
  144.     error_message(junk,j);
  145.     printer_error_flag = 1;
  146. return 0;
  147. }
  148.